#pragma once

#define SINGLE_THREADED 1

#pragma warning( disable: 4640 ) // 'instance' : construction of local static object is not thread-safe
#pragma warning( disable: 4711 ) // function 'function' selected for inline expansion
#pragma warning( disable: 4820 ) // 'identifier' : 'bytes' bytes padding added after construct 'member_name'

#define _AFX_ALL_WARNINGS
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#define _ATL_NO_PRAGMA_WARNINGS
#define _SECURE_ATL 1
#define STRICT
#define VC_EXTRA_LEAN
#define WIN32_LEAN_AND_MEAN

#if _DEBUG
#	define _CRTDBG_MAP_ALLOC
#endif

#if SINGLE_THREADED
#	define _ATL_APARTMENT_THREADED
#else
#	define _ATL_FREE_THREADED
#endif

#include "targetver.h"

#if _DEBUG
#	include <cerrno>
#	include <cstdlib>

#	include <malloc.h>
#	include <crtdbg.h>

#	include <new.h>
#	include <new>
#endif

#pragma warning( push )
#pragma warning( disable: 4100 ) // 'identifier' : unreferenced formal parameter
#pragma warning( disable: 4191 ) // 'operator/operation' : unsafe conversion from 'type of expression' to 'type required'
#pragma warning( disable: 4255 ) // 'function' : no function prototype given: converting '()' to '(void)'
#pragma warning( disable: 4263 ) // 'function' : member function does not override any base class virtual member function
#pragma warning( disable: 4264 ) // 'virtual_function' : no override available for virtual member function from base 'class'; function is hidden
#pragma warning( disable: 4266 ) // 'function' : no override available for virtual member function from base 'type'; function is hidden
#pragma warning( disable: 4365 ) // 'action' : conversion from 'type_1' to 'type_2', signed/unsigned mismatch
#pragma warning( disable: 4555 ) // expression has no effect; expected expression with side-effect
#pragma warning( disable: 4619 ) // #pragma warning : there is no warning number 'number'
#pragma warning( disable: 4625 ) // 'derived class' : copy constructor could not be generated because a base class copy constructor is inaccessible
#pragma warning( disable: 4626 ) // 'derived class' : assignment operator could not be generated because a base class assignment operator is inaccessible
#pragma warning( disable: 4668 ) // 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
#pragma warning( disable: 4917 ) // 'declarator' : a GUID can only be associated with a class, interface or namespace
#pragma warning( disable: 4986 ) // 'function': exception specification does not match previous declaration
#pragma warning( disable: 4987 ) // nonstandard extension used: enum 'enum' used in qualified name
#	include <afxwin.h>
#	include <afxext.h>
#	include <afxcmn.h>
#	include <afxcontrolbars.h>
#	include <afxdialogex.h>
#pragma warning( pop )

#pragma warning( push )
#pragma warning( disable: 4191 ) // 'operator/operation' : unsafe conversion from 'type of expression' to 'type required'
#pragma warning( disable: 4263 ) // 'function' : member function does not override any base class virtual member function
#pragma warning( disable: 4264 ) // 'virtual_function' : no override available for virtual member function from base 'class'; function is hidden
#pragma warning( disable: 4265 ) // 'class' : class has virtual functions, but destructor is not virtual
#pragma warning( disable: 4365 ) // 'action' : conversion from 'type_1' to 'type_2', signed/unsigned mismatch
#pragma warning( disable: 4619 ) // #pragma warning : there is no warning number 'number'
#pragma warning( disable: 4946 ) // reinterpret_cast used between related classes: 'class1' and 'class2'
#pragma warning( disable: 4987 ) // nonstandard extension used: enum 'enum' used in qualified name
#	include <atlbase.h>
#	include <atlcom.h>
#	include <atlctl.h>
#pragma warning( pop )

#include "Resource.h"

using namespace ATL;
using namespace std;

#if SINGLE_THREADED
typedef CComSingleThreadModel CTestClientThreadModel;
#else
typedef CComMultiThreadModel CTestClientThreadModel;
#endif

#include "Debug.h"

#include "../PanicButton/PanicButton_i.h"
#include "TestClient_i.h"

#include "PanicButtonEventSink.h"
#include "TestClient.h"
#include "TestClientDlg.h"
#include "AboutDlg.h"

//
// Helpful utility functions
//

#undef ZeroMemory

template<typename T> inline void ZeroMemory( T& t ) {
	RtlZeroMemory( &t, sizeof( T ) );
}

template<typename T> inline void ZeroMemory( T* t ) {
	RtlZeroMemory( t, sizeof( T ) );
}

template<typename T> inline void ZeroMemory( T* t, const size_t size ) {
	RtlZeroMemory( t, size );
}

inline void BreakIfDebuggerPresent( void ) {
	if ( IsDebuggerPresent( ) ) {
		DebugBreak( );
	}
}

inline void CloseHandleIfNotEqual( HANDLE& toClose, HANDLE value ) {
	if ( toClose != value ) {
		CloseHandle( toClose );
		toClose = value;
	}
}

#ifdef _UNICODE
#	if defined _M_IX86
#		pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#	elif defined _M_X64
#		pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#	else
#		pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#	endif
#endif
